let app: string = 'abc'

function add(a: number, b: number): number {
  return a + b;
}
let a: void = undefined;
function dis(): never {
  while (true) { }

}

let b = 12;



/**
 * 1. string
 * 2. number
 * 3. boolean
 * 4. undefined
 * 5. null
 * 6. void 可以被赋值为undefined，一般表示函数没有返回值
 * 7. never 表示代码永远执行不到
 * 8. any 可以为任何类型
 */



let age: number | string | boolean = 12;
age = '12'
age = true;

let arr: string[] = ['12', '34'] //写法1
let arr3: string[] | number[] = ['12', '34']
let arr1: Array<string> = ['4', 'ui'] // 写法2
let arr2: Array<string | number> = ['4', 'ui', 223]

// 元组

let tuple: [string, string, string | number] = ['1', '2', 9];


// 枚举

enum Color { true, 'green' = 6, 'blue' }

console.log(Color)


function sum(arr: number[]): number {
  return arr.reduce((prev, next) => prev + next);
}
let sum1: (arr: number[]) => number;
sum1 = (arr: number[]): number => arr.reduce((prev, next) => prev + next);


// 用一个对象去表示人

interface Say {
  (): string
}
interface Person {
  name: string,
  age?: number, // age属性可以不存在
  readonly sex: boolean, // 该字段的额值不可以被修改
  sayName: Say
}

const p: Person = {
  name: 'www',
  sex: true,
  sayName() {
    return this.name;
  }
}



interface SquareConfig {
  [x: string]: string | number;
  [x: number]: number;

}
let oo: SquareConfig = {
  1: 78,
  'bac': 'jfiewjo'
}
function createSquare(config: SquareConfig): { color: string; area: number } {
  return { color: 'red', area: 12 }
}
// 利用断言去告诉转换器，我清楚自己传了什么
// 

let c: any = 23;
let mm: string = c as string;